#include<iostream>
#include"TcpServer.hpp"
#include"ServerCal.hpp"
#include<functional>
#include<unistd.h>
//#include"Daemon.hpp"

void Usage(const std::string& proc)
{
    std::cout << "Usage:" << proc << "  clientport" << std::endl;
}

int main(int argc,char* argv[])
{
    if(argc !=2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);

    ServerCal servcal;
    TcpServer* tcpserv = new TcpServer(port,std::bind(&ServerCal::Calculator,&servcal,std::placeholders::_1));
    tcpserv->InitServer();
    //Daemon();
    daemon(0,0);
    tcpserv->Start();

    // Request req(121,2312,'+');
    // std::string s;
    // req.Serialize(&s);
    
    // std::string package = Encode(s);
    // std::cout << package << std::endl; 

    // std::string content;
    // Decode(package,&content);
    // std::cout << content << std::endl;

    // Request req1;
    // req1.DeSerialize(content);
    // std::cout << req1.x << std::endl;
    // std::cout << req1.y << std::endl;
    // std::cout << req1.op << std::endl;

    // Response resp(123,0);
    // std::string s;
    // resp.Serialize(&s);
    // std::cout << s << std::endl; 

    // std::string package = Encode(s);
    // std::cout << package << std::endl; 

    // std::string content;
    // Decode(package,&content);
    // std::cout << content << std::endl;

    // Response resp1;
    // resp1.DeSerialize(content);
    // std::cout << resp1.result << std::endl;
    // std::cout << resp1.code << std::endl;

    return 0;
}